﻿using System;
using System.Collections.Generic;
using System.Text;
using Slf.Formatters;

namespace Slf.Samples.ExtendingLoggerBase
{
  public class ColoredConsoleLogger : LoggerBase
  {
    /// <summary>
    /// Creates a new log entry based on a given log item.
    /// </summary>
    /// <param name="item">Encaspulates logging information.</param>
    /// <exception cref="ArgumentNullException">If <paramref name="item"/>
    /// is a null reference.</exception>
    public override void Log(LogItem item)
    {
      switch (item.LogLevel)
      {
        case LogLevel.Info:
          Console.ForegroundColor = ConsoleColor.Green;
          break;
        case LogLevel.Warn:
          Console.ForegroundColor = ConsoleColor.Cyan;
          break;
        case LogLevel.Error:
          Console.ForegroundColor = ConsoleColor.Yellow;
          break;
        case LogLevel.Fatal:
          Console.ForegroundColor = ConsoleColor.Red;
          break;
        default:
          Console.ResetColor();
          break;
      }


      string loggedText = SimpleLogItemFormatter.Instance.FormatItem(item);
      Console.Out.WriteLine(loggedText);
      Console.ResetColor();
    }
  }
}
